home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Scripts / MergeBranch < prev    next >
Encoding:
Text File  |  1993-05-07  |  4.1 KB  |  174 lines  |  [TEXT/MPS ]

  1. #
  2. #    MergeBranch - Merge a branch revision onto the trunk.
  3. #
  4. #    Usage:    MergeBranch file
  5. #
  6. #    MergeBranch renames the branch revision "file" to "file",branch and
  7. #    checks out the latest revision on the revision trunk for modification.
  8. #
  9. #        If there are no trunk revisions newer than the branch, then the branch
  10. #        is checked in as the latest trunk revision.
  11. #
  12. #        Otherwise MergeBranch brings up both revisions on the screen and
  13. #        puts them side by side.  A menu is appended to the menu bar to assist
  14. #        the user in the merge process.  Checkin the new trunk revision "file"
  15. #        when you finish merging the changes in "file",branch into "file".
  16. #
  17. #    To add MergeBranch to a menu, execute the following command:
  18. #
  19. #        AddMenu Project 'MergeBranch' 'MergeBranch "{Active}" ∑∑ "{WorkSheet}"'
  20. #
  21. #    This script creates three temporary files which are deleted on exit or abort.
  22. #    {ShellDirectory}Compare_File, {ShellDirectory}Compare_State and file,<rev>,
  23. #
  24. #    MergeBranch calls the script CompareFiles.
  25. #
  26. #    © Apple Computer, Inc. 1988 - 1993
  27. #    All rights reserved.
  28.  
  29. Set Exit 0
  30. Begin
  31.     
  32.     #    Check parameters.
  33.     
  34.     If {#} ≠ 1
  35.         Echo "### Usage - {0} file"
  36.         Exit 0
  37.     End
  38.     
  39.     #    Make sure the file exists
  40.  
  41.     If "" == "`Exists -f -q "{1}"`"
  42.         Echo "### {0} - File ∂"{1}∂" not found"
  43.         Exit 4
  44.     End
  45.         
  46.     #    Break apart the pathname.
  47.     
  48.     Set f "{1}"
  49.     If "{f}" =~ /(≈)®1:(≈)®2/
  50.         Set dir "{®1}:"
  51.         Set f "{®2}"
  52.     Else
  53.         Set dir `directory`
  54.         If "{dir}" =~ /(≈)®1:/
  55.             Set dir "{®1}:"
  56.         End
  57.     End
  58.  
  59.     Set path `Files -f "{dir}{f}"`
  60.  
  61.     #    Get project information on the file.
  62.     
  63.     Set info1 "``projectinfo -comments "{path}"``"
  64.  
  65.     If "{{info1}}" =~ /[∂']*(≈)®1,([¬ ∂']+)®2[∂']* ≈Project: (≈∫)®3≈    Task: (≈)®4[ ]«5»Comment: (≈)®5/
  66.         Set file "{®1}"
  67.         Set rev "{®2}"
  68.         Set proj "{®3}"
  69.         Set task "{{®4}}"
  70.         Set comment "Merged from branch {rev}.  {{®5}}"
  71.     End
  72.     
  73.     #    Make sure the file is a branch revision.
  74.  
  75.     If "{rev}" !~ /≈[a-z]≈/
  76.         Alert "File ∂"{f}∂" is not on a branch."
  77.         Exit 4
  78.     End
  79.     
  80.     #    If the branch rev is checked out for modification, check it in
  81.     #     and call projectinfo again to get the branch's new revision number.
  82.     
  83.     If "{rev}" =~ /≈∂+/ OR "{rev}" =~ /≈∂*/
  84.         CheckIn -y "{path}" ≥dev:null                
  85.         Set info1 "``projectinfo "{path}"``"
  86.         If "{{info1}}" =~ /[∂']*(≈)®1,([¬ ∂']+)®2[∂']* ≈Project: (≈∫)®3≈/
  87.             Set file "{®1}"
  88.             Set rev "{®2}"
  89.             Set proj "{®3}"
  90.         End
  91.     End
  92.     
  93.     #    Get projectinfo on the file's latest trunk revision.
  94.     
  95.     Set info2 "``projectinfo -latest -s -project "{proj}" "{f}" ≥ dev:null``"
  96.     If "{{info2}}" == ""
  97.         Alert "Project ∂"{proj}∂" is not mounted."        
  98.         Exit 4
  99.     End
  100.     
  101.     If "{{info2}}" =~ /[∂']*(≈)®1,([¬ ∂']+)®2[∂']*/
  102.         Set file2 "{®1}"
  103.         Set rev2 "{®2}"
  104.     Else
  105.         Alert "Latest rev of File ∂"{f}∂" is checked out for modification.  Cannot merge at this time."        
  106.         Exit 4
  107.     End
  108.     
  109.     #    Is the file open as a window?
  110.     
  111.     Set wind 0
  112.     Unset CaseSensitive
  113.     For i in `Windows`
  114.         If "{path}" =~ /{i}/
  115.             Set wind 1
  116.             Break
  117.         End
  118.     End
  119.  
  120.     #    Rename the branch revision and checkout the trunk revision for modification.
  121.  
  122.     Set branchf "{path},{rev}"
  123.     Rename -y "{path}" "{branchf}"
  124.     CheckOut "{path}" -m -t "{{task}}" -cs "{{comment}}" -project "{proj}"
  125.         
  126.     #    If the revisions on the trunk are older than the branch rev then
  127.     #          checkin the branch on the trunk (we don't need to merge).
  128.     #     Otherwise call comparefiles and let the user do the merge and checkin.
  129.     
  130.     If "{rev}" =~ /{rev2}≈/
  131.     
  132.         Echo "Include ∂"{path}∂" 'ckid';" | Rez -m -a -o "{branchf}" -noResolve output
  133.     
  134.         Rename -y "{branchf}" "{path}"
  135.         
  136.         If "{wind}"
  137.             If "{path}" =~ /"{active}"/
  138.                 Close "{path}"
  139.                 Open "{path}"
  140.             Else
  141.                 Close "{path}"
  142.                 Target "{path}"
  143.             End
  144.         End
  145.         
  146.         CheckIn "{path}"
  147.  
  148.     Else
  149.     
  150.         If Not `Files -t TEXT "{path}"` Or `Exists -a "{path}"`
  151.             Echo "### {0} - Unable to interactively compare non-TEXT files." ≥≥dev:stderr
  152.             Exit 2
  153.         End
  154.  
  155.         Open "{path}"
  156.  
  157.         CompareFiles "{branchf}" "{path}"
  158.  
  159.         If {Status} == 2
  160.             Echo Close ∂""{branchf}"∂" >> "{ShellDirectory}Compare_State"
  161.             Echo Delete ∂""{branchf}"∂" >> "{ShellDirectory}Compare_State"
  162.             Exit 0
  163.         Else If {Status} == 0
  164.                 If "{wind}"
  165.                     Close "{branchf}"
  166.                 End
  167.                 Delete "{branchf}"
  168.                 CheckOut -cancel -y "{path}"
  169.         End
  170.         
  171.     End
  172.  
  173. End
  174.